import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_getx/core/getx/control/base_controller.dart';

import 'login_api.dart';
import 'login_state.dart';

class LoginLogic extends BaseController {

  final LoginState state = LoginState();
  late LoginApi api;

  /*@override
  void onInit() {
    if(!Constant.inProduction) {
      state.nameController.text = "8202826612";
      state.passwordController.text = "123456";
    }
    super.onInit();
  }*/

  @override
  void onReady() {
    /// 显示状态栏和导航栏
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.top, SystemUiOverlay.bottom]);
    api = LoginApi();
    super.onReady();
  }

  void login() {
    if (state.key.currentState?.validate() ?? false) {
      state.key.currentState?.save();
      api.login(state.name, state.pwd);
    } else {
      state.validateMode = AutovalidateMode.always;
      update();
    }
  }

}
